package com.ymatou.iapi.productmanager.testcase;

import java.util.HashMap;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.productmanager.parameter.SetPspTagBean;
import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymatou.iapi.productmanager.service.GetProductAndCatalogInfoCall;
import com.ymatou.iapi.productmanager.service.SetPspTagCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.ProductManagerCallServiceV2;
import com.ymttest.business.service.productdata.impl.ProductFactory;
import com.ymttest.database.sqlwapper.YmtProductsIWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.MapUtil;
/**
*买手设置(或移除)PSP优选
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_SetPspTag{
	private static SetPspTagBean bean;
	private static SetPspTagCall call;
	private static Integer sellerId = Integer.valueOf(EnvSetup.getData("productpriceSellerId"));
	private static Integer sellerId1 = Integer.valueOf(EnvSetup.getData("productsellerid"));
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("买手设置(或移除)PSP优选");
	}

	@Before
	public void caseUp() {
		bean=new SetPspTagBean();
		call=new SetPspTagCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_SetPspTag_001() {
		Logger.start(true,"正例-买手设置(或移除)PSP优选，打标，待加入优选商品2");
		try {
			//创建商品
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
			new YmtProductsIWapper().updatePspStatus(productId,2);
			bean.setProductId(productId);
			bean.setSellerId(sellerId);
			bean.setIsAdd(true);
			call.setData(bean);
			call.callService();			
			Logger.verifyEquals("200", call.getString("Code"), "验证Code");
			Short pspStatus = new YmtProductsIWapper().getPspStatus(productId);
			int i = 3;
			short j = (short)i;
			Logger.verifyEquals(j, pspStatus, "验证pspStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_SetPspTag_002() {
		Logger.start(true,"正例-买手设置(或移除)PSP优选，打标，优选商品4");
		try {
			//创建商品
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
			new YmtProductsIWapper().updatePspStatus(productId,4);
			bean.setProductId(productId);
			bean.setSellerId(sellerId);
			bean.setIsAdd(true);
			call.setData(bean);
			call.callService();			
			Logger.verifyEquals("200", call.getString("Code"), "验证Code");
			Short pspStatus = new YmtProductsIWapper().getPspStatus(productId);
			int i = 3;
			short j = (short)i;
			Logger.verifyEquals(j, pspStatus, "验证pspStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_SetPspTag_003() {
		Logger.start(true,"正例-买手设置(或移除)PSP优选，撤标，待加入优选商品4");
		try {
			//创建商品
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
			new YmtProductsIWapper().updatePspStatus(productId,4);
			bean.setProductId(productId);
			bean.setSellerId(sellerId);
			bean.setIsAdd(false);
			call.setData(bean);
			call.callService();			
			Logger.verifyEquals("200", call.getString("Code"), "验证Code");
			Short pspStatus = new YmtProductsIWapper().getPspStatus(productId);
			int i = 4;
			short j = (short)i;
			Logger.verifyEquals(j, pspStatus, "验证pspStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_SetPspTag_006() {
		Logger.start(true,"反例-买手设置(或移除)PSP优选-商品不是优选-买手是优选买手");
		try {
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
			YmtProductsIWapper ymtProductsIWapper = new YmtProductsIWapper();
			//ymtProductsIWapper.updatePspStatus(productId,0);
			
			bean.setProductId(productId);
			//不是优选买手
			bean.setSellerId(sellerId);
			bean.setIsAdd(true);
			call.setData(bean);
			call.callService();				
			Logger.verifyEquals("201", call.getString("Code"), "验证Code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}